<template>
  <div class="box4" ref="map">地图</div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
import ChinaJSON from './China.json' //中国地图经纬度的json数据
let map = ref()
//注册中国地图
echarts.registerMap('china', ChinaJSON as any)
onMounted(() => {
  let mycharts = echarts.init(map.value)
  //echarts配置项
  mycharts.setOption({
    //地图组件
    geo: {
      map: 'china',
      roam: true, //鼠标缩放效果
      top: 200,
      //地图的文字设置
      label: {
        show: true,
        color: 'white',
        fontSize: 10,
      },
      itemStyle: {
        //可设置渐变
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: '#8882A1', // 0% 处的颜色
            },
            {
              offset: 1,
              color: '#F6F6F6', // 100% 处的颜色
            },
          ],
          global: false, // 缺省为 false
        },
        //透明度
        opacity: 0.7,
      },
      //高亮效果
      emphasis: {
        itemStyle: {
          color: '#FAEEE7',
        },
        label: {
          fontSize: 30,
        },
      },
    },
    //布局位置
    grid: {
      top: 0,
      left: 0,
      bottom: 0,
      right: 0,
    },
    //航线设置
    series: [
      {
        type: 'lines', //航线的系列
        data: [
          {
            coords: [
              [116.405258, 39.904989], //起点
              [119.306239, 26.075302], //终点
            ],
            //航线统一样式设置
            lineStyle: {
              color: 'orange',
              width: 5,
            },
          },
          {
            coords: [
              [116.405258, 39.904989], //起点
              [114.298527, 30.584355], //终点
            ],
            //航线统一样式设置
            lineStyle: {
              color: 'blue',
              width: 5,
            },
          },
        ],
        //开启动画特效
        effect: {
          show: true,
          symbol: 'arrow', //动画样式
          color: 'red',
          symbolSize: 20,
        },
      },
    ],
  })
})
</script>

<style scoped lang="scss"></style>
